package s6;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class Tree {
	
	private List<Node> list=new LinkedList<Node>(); 
	private Node root=null;
	public Tree(){ }
	
	public void addRootNode(Node node){
		root=new Node(null,node.getNodeSelf());
		list.add(root);
	}
	public void add(Node node){
		boolean check=this.checkFatherNode(node);
		if(check){
		   list.add(node);
		}
	}
	private boolean checkFatherNode(Node node){
		boolean mark=false;
		String father =node.getFather();
		Iterator<Node> iter=list.iterator();
		while(iter.hasNext()){
			Node nd=iter.next();
			if(nd.getNodeSelf().equals(father)){
				mark=true;
			}
		}
		return mark;
	}
	
	public void showTree(){
		
		Iterator<Node> iter=list.iterator();
		while(iter.hasNext()){
			Node nd=iter.next();
			System.out.println(nd.getFather()+"-"+nd.getNodeSelf());
			}
		}

	public List<Node> getList() {
		return list;
	}
	public Node getRootNode(){
		return root;
	}
}
